﻿using Dapper;
using IntelligentGateway.Tools;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace IntelligentGateway.Data
{
    public static class SqlExtensions
    {
        public static bool UpdateDemand<T>(this IDbConnection connection, T entityToUpdate, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
        {
            string sql = SqlBuilderTools.GenarateUpdateStr(entityToUpdate);
            int count = connection.Execute(sql, null, transaction);
            return count > 0;
        }
        public static bool DeleteDemand<T>(this IDbConnection connection, T entityToUpdate, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
        {
            string sql = SqlBuilderTools.GenarateDeleteStr(entityToUpdate);
            if (string.IsNullOrEmpty(sql)) return false;
            int count = connection.Execute(sql, null, transaction);
            return count > 0;
        }
    }
}
